﻿package 
{
	import flash.display.*;
	import flash.events.*;
	import flash.utils.*;
	
	public class UIButton extends Sprite
	{
		private var buttonBitmap:Bitmap;
		
		public function UIButton (className:String, Width:int, Height:int)
		{
			var bitmapClass:Class;
			var myBitMapData:BitmapData;
			
			bitmapClass = getDefinitionByName(className) as Class;
			if (bitmapClass)
			{
				myBitMapData = new bitmapClass(Width, Height);
				buttonBitmap = new Bitmap(myBitMapData);
				addChild(buttonBitmap);
	
				this.addEventListener(MouseEvent.CLICK, onClick);
				this.addEventListener(MouseEvent.MOUSE_OVER, onMoveOver);
				this.addEventListener(MouseEvent.MOUSE_OUT, onMoveOut);
			}
			else 
			{
				trace("Error get Button Image");
			}
			
		}
		
		public function onClick(event:Event)
		{	
			dispatchEvent(new SimLifeEvents(SimLifeEvents.PETMOVE));	
		}
		
		public function onMoveOver(event:Event)
		{
			buttonBitmap.scaleX = 1.2;
			buttonBitmap.scaleY = 1.2;
		}
		
		public function onMoveOut(event:Event)
		{
			buttonBitmap.scaleX = 1;
			buttonBitmap.scaleY = 1;
		}
	}
}